package com.ruoyi.system.service.award.party.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.award.party.PartyAwardInfo;
import com.ruoyi.system.domain.honor.team.TeamHonor;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.award.party.PartyAwardInfoMapper;
import com.ruoyi.system.service.award.party.IPartyAwardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

/**
 * 党建获奖Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-07
 */
@Service
public class PartyAwardInfoServiceImpl implements IPartyAwardInfoService
{
    @Autowired
    private PartyAwardInfoMapper partyAwardInfoMapper;
    @Autowired
    private SysDeptMapper syeDeptMapper   ;
    /**
     * 查询党建获奖
     * 
     * @param id 党建获奖主键
     * @return 党建获奖
     */
    @Override
    public PartyAwardInfo selectPartyAwardInfoById(Long id)
    {
        PartyAwardInfo ra = partyAwardInfoMapper.selectPartyAwardInfoById( id);
        if(ra.getDeptId()!=null){
            ra.setDeptName(syeDeptMapper.selectDeptById(ra.getDeptId()).getDeptName());
        }
        return ra;
    }

    /**
     * 查询党建获奖列表
     * 
     * @param partyAwardInfo 党建获奖
     * @return 党建获奖
     */
    @Override
    public List<PartyAwardInfo> selectPartyAwardInfoList(PartyAwardInfo partyAwardInfo)
    {
        //部门权限
        if(partyAwardInfo.getCurrentRole()!=null&&partyAwardInfo.getCurrentRole().equals("department")){
            partyAwardInfo.setDeptId(SecurityUtils.getDeptId());
        }
        return partyAwardInfoMapper.selectPartyAwardInfoList(partyAwardInfo);
    }

    /**
     * 新增党建获奖
     * 
     * @param partyAwardInfo 党建获奖
     * @return 结果
     * 党建不存在个人 所以只使用部门缓存
     */
    @Override
    @CacheEvict(
            value = "departmentStatistics_getIndexInfo",
            key = "T(com.ruoyi.common.utils.SecurityUtils).getDeptId() + '-' + T(java.time.format.DateTimeFormatter).ofPattern('yyyy').format(T(java.time.Instant).ofEpochMilli(#partyAwardInfo.issueTime.time).atZone(T(java.time.ZoneId).systemDefault()).toLocalDate())"
    )
    public int insertPartyAwardInfo(PartyAwardInfo partyAwardInfo)
    {
        Long deptId = SecurityUtils.getDeptId();
        partyAwardInfo.setDeptId(deptId);
        return partyAwardInfoMapper.insertPartyAwardInfo(partyAwardInfo);
    }

    /**
     * 修改党建获奖
     * 
     * @param partyAwardInfo 党建获奖
     * @return 结果
     */
    @Override
    public int updatePartyAwardInfo(PartyAwardInfo partyAwardInfo)
    {
        return partyAwardInfoMapper.updatePartyAwardInfo(partyAwardInfo);
    }

    /**
     * 批量删除党建获奖
     * 
     * @param ids 需要删除的党建获奖主键
     * @return 结果
     */
    @Override
    public int deletePartyAwardInfoByIds(Long[] ids)
    {
        return partyAwardInfoMapper.deletePartyAwardInfoByIds(ids);
    }

    /**
     * 删除党建获奖信息
     * 
     * @param id 党建获奖主键
     * @return 结果
     */
    @Override
    public int deletePartyAwardInfoById(Long id)
    {
        return partyAwardInfoMapper.deletePartyAwardInfoById(id);
    }
}
